package com.centling.bluecollar.login.DAO;
import java.util.ArrayList;  
import java.util.List;  
  

import org.hibernate.Query;  
import org.hibernate.Session;  
import org.hibernate.Transaction;  
import org.springframework.stereotype.Repository;  
import org.springframework.util.AntPathMatcher;  
import org.springframework.util.PathMatcher;  

import com.centling.bluecollar.login.entity.Perm;
  
@Repository  
public class PermDAO extends BaseDAO implements IPermDAO {  
  
    @Override  
    public void save(Perm perm) {  
        // TODO Auto-generated method stub  
  
    }  
  
    @Override  
    public void delete(Perm perm) {  
        // TODO Auto-generated method stub  
  
    }  
  
    @Override  
    public Perm findPermById(String id) {  
        // TODO Auto-generated method stub  
        return null;  
    }  
  
    @Override  
    public Perm findPermByPermname(String permname) {  
        // TODO Auto-generated method stub  
        return null;  
    }  
  
    @Override  
    public List<Perm> findPermByUri(String requestUri) {  
        Session s = getSession();  
        Query query = s.createQuery("from Perm");  
        List<Perm> permlist = query.list();  
        List<Perm> perms = new ArrayList<Perm>();  
        for (Perm perm : permlist) {  
            if (urlMatcher(perm.getPermstr(), requestUri))  
                perms.add(perm);  
        }  
        return perms;  
    }  
  
    private boolean urlMatcher(String permstr, String requestUri) {  
        boolean isMatcher = false;  
        PathMatcher matcher = new AntPathMatcher();  
        isMatcher = matcher.match(permstr, requestUri);  
        return isMatcher;  
    }  
  
    @Override  
    public List findByProperty(String propertyName, Object value) {  
        // TODO Auto-generated method stub  
        return null;  
    }  
  
}  
